package org.dtrevien.metamodel.java;

import java.util.ArrayList;
import java.util.List;

import org.dtrevien.metamodel.java.visitor.Visitor;

/**
 * Class representation 
 * It contains all attributes, methods, imports, package, constructor, extends
 * 
 * @author davidtrevien
 *
 */
public class Classe {

	protected String name;
	protected String classpath;
	protected boolean abstraction = false;

	protected Constructeur constructeur;
	
	protected List<Attribut> attributs;
	protected List<Import> imports;
	protected List<ClasseExtendReference> extend;
	protected List<Methode> methods;
	protected List<ClasseImplementReference> implementation;
	
	public Classe(String name, String clathpath) {
		this.name = name;
		this.classpath = clathpath;
		this.attributs = new ArrayList<Attribut>();
		this.constructeur = new Constructeur(name);
		this.imports = new ArrayList<Import>();
		this.extend = new ArrayList<ClasseExtendReference>();
		this.methods = new ArrayList<Methode>();
		this.implementation = new ArrayList<ClasseImplementReference>();
	}
	
	public void setClasspath(String c) {
		this.classpath = c;
	}
	
	public String getClasspath() {
		return this.classpath;
	}
	
	public String getName() {
		return this.name;
	}
	
	public List<Attribut> getAttributs() {
		return this.attributs;
	}
	
	public void setAttributs(List<Attribut> attr) {
		this.attributs = attr;
	}
	
	public Attribut getAttribut(String type) {
		for(Attribut a : this.attributs) {
			if (a.getType().getName().equals(type)) return a;
		}
		return null;
	}
	
	public List<ClasseExtendReference> getExtends() {
		return this.extend;
	}

	public void setExtends(List<ClasseExtendReference> extend) {
		this.extend = extend;
	}

	public List<Import> getImports() {
		return this.imports;
	}
	
	public boolean addImport(Import i) {
		if (this.imports.contains(i)) return false;
		else this.imports.add(i);
		return true;
	}
	
	public void setImports(List<Import> i) {
		this.imports = i;
	}
	
	public Constructeur getConstructeur() {
		return this.constructeur;
	}
	
	public void accept(Visitor v) {
		v.visiteClasse(this);
	}
	
	@Override
	public boolean equals(Object o) {
		if (o instanceof Classe) {
			return ((Classe)o).getName().equals(this.getName());
		}
		return false;
	}

	public void setAsAbstract(boolean b) {
		this.abstraction = b;
	}
	
	public boolean isAbstract() {
		return this.abstraction;
	}

	public boolean isAbstraction() {
		return this.abstraction;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setConstructeur(Constructeur constructeur) {
		this.constructeur = constructeur;
	}

	public void setAbstraction(boolean abstraction) {
		this.abstraction = abstraction;
	}

	public List<Methode> getMethods() {
		return this.methods;
	}

	public void setMethods(List<Methode> methods) {
		this.methods = methods;
	}

	public List<ClasseImplementReference> getImplementations() {
		return this.implementation;
	}

	public void setImplementations(List<ClasseImplementReference> implementation) {
		this.implementation = implementation;
	}
}
